package cn.kgc.ubagnet.service.order;

import cn.kgc.ubagnet.mapper.OrderMapper;
import cn.kgc.ubagnet.mapper.OrderProImgDetailAddressMapper;
import cn.kgc.ubagnet.pojo.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService{
    @Resource
    OrderMapper orderMapper;
    @Resource
    OrderProImgDetailAddressMapper orderProImgDetailAddressMapper;

    @Override
    public int Ordersave(Order order) {
        if(order.getId()!=null){//修改
            return orderMapper.updateByPrimaryKeySelective(order);
        }else{//添加
            return orderMapper.insertSelective(order);
        }

    }


    @Override
    public List<OrderProImgDetailAddress> OrderListBydetailid(Long detailiid) {
        OrderProImgDetailAddressExample orderExample=new OrderProImgDetailAddressExample();
        orderExample.createCriteria().andOrderdetailsidEqualTo(detailiid);
        List<OrderProImgDetailAddress> orders = orderProImgDetailAddressMapper.selectByExample(orderExample);
        return orders;
    }

    @Override
    public PageInfo<OrderProImgDetailAddress> OrderPageInfoBytype(Integer userid, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.orderBy("createdate desc");
        PageHelper.startPage(pageNum,pageSize);
        OrderProImgDetailAddressExample orderExample=new OrderProImgDetailAddressExample();
        OrderProImgDetailAddressExample.Criteria criteria=orderExample.createCriteria();
        criteria.andUseridEqualTo(userid);
        if(status!=0){
        criteria.andStatusEqualTo(status);
        }

        PageInfo<OrderProImgDetailAddress> pageInfo=new PageInfo<>(orderProImgDetailAddressMapper.selectByExample(orderExample));

        return pageInfo;
    }

    @Override
    public Order OrderById(Integer id) {
        return orderMapper.selectByPrimaryKey(id);
    }
}
